//
//  HSYAlertView+Animation.m
//  高仿暴走斗图
//
//  Created by key on 16/4/6.
//  Copyright © 2016年 huangsongyao. All rights reserved.
//

#import "HSYAlertView+Animation.h"
#import "HSYAnimationHelper.h"

@implementation HSYAlertView (Animation)


#pragma mark - AlertView Animation

- (void)zoomIn {
    
    CGAffineTransform transf = CGAffineTransformIdentity;
    self.backgroundView.transform = CGAffineTransformScale(transf, 0.0f, 0.0f);
    @weakify(self);
    [UIView animateWithDuration:0.4 animations:^{
        
        @strongify(self);
        self.backgroundView.transform = CGAffineTransformScale(transf, 1.2f, 1.2f);
        
    } completion:^(BOOL finished) {
        
        [UIView animateWithDuration:0.3 animations:^{
            
            @strongify(self);
            self.backgroundView.transform = CGAffineTransformScale(transf, 1.0f, 1.0f);
            
        } completion:^(BOOL finished) {
            
            @strongify(self);
            self.isDisplay = YES;
            self.animationType = kCustomAlertViewAnimationTypeZoomOut;
        }];
    }];
}


- (void)zoomOut {
    
    CGAffineTransform transf = CGAffineTransformIdentity;
    @weakify(self);
    [UIView animateWithDuration:0.3 animations:^{
        
        @strongify(self);
        self.backgroundView.transform = CGAffineTransformScale(transf, 1.2f, 1.2f);
        
    } completion:^(BOOL finished) {
        
        [UIView animateWithDuration:0.4 animations:^{
            
            @strongify(self);
            self.backgroundView.transform = CGAffineTransformScale(transf, 0.2f, 0.2f);
            
        } completion:^(BOOL finished) {
            
            @strongify(self);
            self.isDisplay = NO;
            [self removeFromSuperview];
            if (self.selectButton) {
                self.selectButton(self, 0);
            }
        }];
        
    }];
}


- (void)fadeIn {
    
    self.backgroundView.alpha = 0.0f;
    @weakify(self);
    [UIView animateWithDuration:[self duration] delay:[self delay] options:UIViewAnimationOptionCurveEaseIn animations:^{
        
        @strongify(self);
        self.backgroundView.alpha = 1.0;
        
    } completion:^(BOOL finished) {
        
        @strongify(self);
        self.isDisplay = YES;
        self.animationType = kCustomAlertViewAnimationTypeFadeOut;//淡出出去
    }];
}

- (void)fadeOut {
    
    @weakify(self);
    [UIView animateWithDuration:[self duration] animations:^ {
        
        @strongify(self);
        self.alpha = 0.0f;
    } completion:^(BOOL finished) {
        
        @strongify(self);
        self.isDisplay = NO;
        [self removeFromSuperview];
        
        if (self.selectButton) {
            self.selectButton(self, 0);
        }
    }];
}


- (void)moveIn {
    
    @weakify(self);
    [UIView animateWithDuration:[self duration] delay:[self delay] options:UIViewAnimationOptionTransitionCurlDown animations:^{
        
        @strongify(self);
        self.backgroundView.frame = CGRectMake(0, 0, IPHONE_WIDTH, IPHONE_HEIGHT);
        self.backgroundImage.frame = self.backgroundView.frame;
        
    } completion:^(BOOL finished) {
        
        @strongify(self);
        self.isDisplay = YES;
        self.animationType = kCustomAlertViewAnimationTypeMoveOut;//平移出去
    }];
}

- (void)moveOut {
    
    @weakify(self);
    [UIView animateWithDuration:[self duration] delay:[self delay] options:UIViewAnimationOptionTransitionCurlDown animations:^{
        
        @strongify(self);
        self.backgroundView.frame = CGRectMake(0, IPHONE_HEIGHT, IPHONE_WIDTH, IPHONE_HEIGHT);
        self.backgroundImage.frame = self.backgroundView.frame;
        
    } completion:^(BOOL finished) {
        
        @strongify(self);
        self.isDisplay = NO;
        [self removeFromSuperview];
        if (self.selectButton) {
            self.selectButton(self, 0);
        }
    }];
}

- (CGFloat)duration {
    
    return 0.5f;
}

- (CGFloat)delay {
    
    return 0.0f;
}

@end
